import Mock from "mockjs";

let { data } = Mock.mock({
  "data|10": [
    {
      "id|+1": 1,
      title: "@ctitle",
      content: "@cparagraph",
      img: "@image(100x100, @color, @color, @ctitle)",
    },
  ],
});

// Mock.mock可以模拟接口
Mock.mock("/api/notice/list", "get", () => {
  return {
    success: true,
    data: data,
    count: data.length,
  };
});

Mock.mock("/api/notice/remove", "post", (options) => {
  const { id } = JSON.parse(options.body);
  if (!id) {
    return {
      success: false,
      message: "id不能为空",
    };
  } else {
    data = data.filter((item) => item.id !== id);
    return {
      success: true,
      message: "删除成功",
      data: data,
    };
  }
});
